﻿using System.Collections.Generic;
using System.Linq;
using Dapper;

namespace ExtendLib.Helper
{
    /// <summary>
    /// 从指定网站获取代理Ip  
    /// </summary>
    [Table("ProxyIpConfig")]
    public class ProxyParseModel
    {
        [Key]
        public int? Id { get; set; }
        /// <summary>
        /// 代理Ip所在网址
        /// </summary>
        public string WebUrl { get; set; }
        /// <summary>
        /// 解析网址的Class选择器 使用的Jumony Core解析
        /// </summary>
        public string SelectRule { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public string Status { get; set; }
    }
    /// <summary>
    /// 数据库操作帮助类
    /// </summary>
    public class ProxyParseHelper
    {
        /// <summary>
        /// 新增和编辑实体
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Create(ProxyParseModel model)
        {
            //为空插入 否则编辑模式
            int r = (model.Id == null ? DbHelperByDapper.InsertDb(model) : DbHelperByDapper.ModifyDb(model));
            if (r > 0)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 获取所有配置网站
        /// </summary>
        /// <returns></returns>
        public static List<ProxyParseModel> GetAll()
        {
            var list=DbHelperByDapper.GetList<ProxyParseModel>(new {}).ToList();
            return list;
        }
        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static ProxyParseModel GetItem(int? key)
        {
            return DbHelperByDapper.GetModel<ProxyParseModel>(key);
        }
    }

}
